from mysql.connector import Error
import mysql.connector
import pandas as pd
try:
    mydb = mysql.connector.connect(

        host="bmckean.dynu.net",
        user="msurf-script",
        passwd="Capstone#2019",
        database="metasurface_design"

    )
    mycursor = mydb.cursor()
    print(mydb.is_connected())
except Error as e:
    print(e)
try:
    query = "SELECT * from dogbone_simulations;"
    mycursor.execute(query)
    results = mycursor.fetchall()
    mydb.commit()
    tab_name = "dogbone_simulations"
    query = "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = \"%s\";" % (tab_name)
    mycursor.execute(query)
    colsqur = mycursor.fetchall()
    cols = []
    for col in colsqur:
        col = str(col[0])
        cols.append(col)
    mydb.commit()
except Error as e:
    print("Error reading data from MySQL table", e)
df1 = pd.DataFrame(results)
df1.to_pickle("sim_results.pkl")